package com.example.task03;
import java.io.File;

import android.Manifest;
import android.annotation.SuppressLint;
import android.app.SearchManager;
import android.content.Intent;
import android.content.pm.PackageManager;
import android.graphics.Bitmap;
import android.net.Uri;
import android.os.Build;
import android.os.Bundle;
import android.os.StrictMode;
import android.view.View;
import android.widget.Button;
import android.widget.EditText;
import android.widget.ImageView;
import android.widget.RadioButton;
import android.widget.RadioGroup;
import android.widget.Toast;

import androidx.appcompat.app.AppCompatActivity;
import androidx.core.app.ActivityCompat;

public class MainActivity extends AppCompatActivity {
    private RadioGroup radioGroup1;
    private RadioButton radioButton1;
    private RadioButton radioButton2;
    private EditText editText1;
    private EditText editText2;
    private Button button1;
    private Intent intent = null;
    String gender = null;

    public MainActivity() {
    }

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        radioButton1 = findViewById(R.id.rbtn_male);
        radioButton2 = findViewById(R.id.rbtn_female);
        editText1 = findViewById(R.id.et_height);
        editText2 = findViewById(R.id.et_weight);
        radioGroup1 = findViewById(R.id.gender);
        button1 = findViewById(R.id.btn_result);
        radioGroup1.setOnCheckedChangeListener(new RadioGroup.OnCheckedChangeListener() {
            @Override
            public void onCheckedChanged(RadioGroup radioGroup, int checkedId) {
                RadioButton radioButton = (RadioButton) findViewById(checkedId);
                gender = (String) radioButton.getText();
            }
        });
        button1.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View view) {
                if(gender==null) {
                    Toast.makeText(MainActivity.this, "请选择性别！", Toast.LENGTH_SHORT).show();
                }else{
                    if(intent==null){
                        intent = new Intent(MainActivity.this,ResultActivity.class);
                        String height = String.valueOf(editText1.getText());
                        String weight = String.valueOf(editText2.getText());
                        intent.putExtra("height",height);
                        intent.putExtra("weight",weight);
                        intent.putExtra("gender",gender);
                        startActivity(intent);
                    }
                }

            }
        });
    }

}
